﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Jemgine.Engine
{
	public class Selection : IComparable<Selection>
	{
		public static Selection None { get { return new Selection(Types.None, 0, 0, 0); } }

		public enum Types
		{
            None,
            MapElement,
            EntityElement,
            Vertex,
            Anchor,
        }

		public Types Type;
		public int TopIndex;
		public int MiddleIndex;
        public int BottomIndex;

        public Selection(Types _type, int _Top, int _Middle, int _Bottom)
		{
			Type = _type;
			TopIndex = _Top;
			MiddleIndex = _Middle;
			BottomIndex = _Bottom;
		}

        public static bool operator ==(Selection a, Selection b)
		{
			if (a.Type != b.Type) return false;
			if (a.TopIndex != b.TopIndex) return false;
			if (a.MiddleIndex != b.MiddleIndex) return false;
			if (a.BottomIndex != b.BottomIndex) return false;
			return true;
		}

		public static bool operator !=(Selection a, Selection b)
		{
			if (a.Type != b.Type) return true;
			if (a.TopIndex != b.TopIndex) return true;
			if (a.MiddleIndex != b.MiddleIndex) return true;
			if (a.BottomIndex != b.BottomIndex) return true;
			return false;
		}

		public override int GetHashCode()
		{
			return (int)(TopIndex << 24) + (MiddleIndex << 8) + BottomIndex;
		}

		public override bool Equals(object obj)
		{
			if (!(obj is Selection)) return false;
			return this == (obj as Selection);
		}


        #region IComparable<Selection> Members

        public int CompareTo(Selection other)
        {
            return this.GetHashCode() - other.GetHashCode();
        }

        #endregion
    }
}
